package com.nbsaas.boot.shopArticle.data.entity;

import com.nbsaas.boot.code.annotation.*;
import com.nbsaas.boot.jpa.data.entity.AbstractEntity;
import com.nbsaas.boot.rest.enums.StoreState;
import com.nbsaas.boot.rest.filter.Operator;
import com.nbsaas.boot.shop.data.entity.Shop;
import lombok.Data;
import org.hibernate.annotations.Comment;

import javax.persistence.*;
import java.util.Date;

/**
 * 文章
 *
 * @author 年高
 */

@FormAnnotation(title = "资讯")
@BeanExt(items = {
        @FormExtField(title = "文章内容",parent = "document",parentField = "note", fieldName = "note", fieldClass = String.class,simple = false)

})
@SearchBean(
        items = {
                @SearchItem(label = "分类名称",name = "catalogName",key = "catalog.name",show = false)
        }
)
@Data
@Entity
@Table(name = "bs_shop_article")
public class ShopArticle extends AbstractEntity {

    public static ShopArticle fromId(Long id){
        ShopArticle result=new ShopArticle();
        result.setId(id);
        return result;
    }

    /**
     * 文章标题
     */
    @SearchItem(label = "标题",name = "title")
    @FormField(title = "标题",  grid = true, col = 22,width = "300")
    private String title;

    /**
     * 文章图片集
     */
    @FormField(title = "资讯主图", col = 22,type = InputType.image)
    private String logo;


    /**
     * 文章分类
     *
     */

    @FieldName
    @FieldConvert
    @FormField(title = "文章分类", grid = true, col = 22,type = InputType.select,option = "shopArticleCatalog")
    @SearchItem(label = "文章分类",name = "catalog",key = "catalog.id",classType = Long.class,operator = Operator.eq,type = InputType.select)
    @ManyToOne(fetch = FetchType.LAZY)
    private ShopArticleCatalog catalog;


    @SearchItem(label = "商家", name = "shop", key = "shop.id", operator = Operator.eq, classType = Long.class,show = false)
    @Comment("商家id")
    @JoinColumn(name = "shop_id")
    @FieldConvert
    @FieldName
    @ManyToOne(fetch = FetchType.LAZY)
    private Shop shop;




    /**
     * 文章评论数量
     */
    private Integer comments;

    /**
     * 喜欢的数量
     */
    private Integer likes;


    /**
     * 文章内容
     */
    @FieldConvert
    @ManyToOne(fetch = FetchType.LAZY)
    private ShopArticleDocument document;

    /**
     * 文章扩展信息
     */
    private String extData;


    /**
     * 文章图片集
     */
    private String images;

    /**
     * 封面
     */
    private String img;


    /**
     * 点赞数量
     */
    private Integer ups;

    /**
     * 文章查看数量
     */
    private Integer views;

    private StoreState storeState;

    /**
     * 添加时间
     */
    @FormField(title = "添加时间",  grid = true, ignore = true,width = "1000")
    @Comment("添加时间")
    private Date addDate;

    /**
     * 最新修改时间
     */
    @Comment("最新修改时间")
    private Date lastDate;
}
